package me.jessyan.mvparms.demo.mvp.ui.adapter;

import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;

import com.jess.arms.base.BaseHolder;
import com.jess.arms.base.DefaultAdapter;

import java.util.List;

import me.jessyan.mvparms.demo.R;

/**
 * @author DrChen
 * @Date 2019/3/10.
 * qq:1414355045
 */
public class SelectTicketAdapter extends DefaultAdapter<String> {
    private int selected = -1;

    public SelectTicketAdapter(List<String> infos ) {
        super(infos, false);
    }

    public void setSelected(int position){
        this.selected = position;
        notifyDataSetChanged();
    }
    @Override
    public BaseHolder getHolder(View v, int viewType) {
        return new BaseHolder<String>(v) {


            @Override
            public void setData(String data, int position) {
                CheckBox cb   = v.findViewById(R.id.cb);
                TextView textView = v.findViewById(R.id.tv);
                if(selected==position){
                    cb.setChecked(true);
                }else {
                    cb.setChecked(false);
                }
                textView.setText(data);

            }
        };
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.item_select_ticket;
    }
}
